<template>
  <div class="task-table">
    <el-table :data="tableList" border max-height="520" style="width: 100%;">
      <el-table-column label="序号" align="center" width="80">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="检验单号" align="center" width="180">
        <template #default="scope">
          <!-- <el-button type="primary" link @click="pushCheckDetails(scope.row)"> -->
            {{scope.row.codeNo}}
          <!-- </el-button> -->
        </template>
      </el-table-column>
      <el-table-column label="工序任务单号" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.taskCodeNo) }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" width="150">
        <template #default="scope">
          {{ selectDictLabel(data_status, scope.row.dataStatus) }}
        </template>
      </el-table-column>
      <el-table-column label="检验类型" align="center" width="150">
        <template #default="scope">
          {{ selectDictLabel(check_type, scope.row.checkType) }}
        </template>
      </el-table-column>
      <el-table-column label="物料编码" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterFullCode) }}
        </template>
      </el-table-column>
      <el-table-column label="物料名称" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterName) }}
        </template>
      </el-table-column>
      <el-table-column label="助记码" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
        </template>
      </el-table-column>
      <el-table-column label="规格型号" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterSpecModel) }}
        </template>
      </el-table-column>
      <el-table-column label="单轨长度" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.monorailLength) }}
        </template>
      </el-table-column>
      <el-table-column label="本次任务数量" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.checkNums) }}
        </template>
      </el-table-column>
      <el-table-column label="基本单位" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.unitName) }}
        </template>
      </el-table-column>
      <el-table-column label="辅助数量" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.assistNums) }}
        </template>
      </el-table-column>
      <el-table-column label="辅助单位" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.assistUnitName) }}
        </template>
      </el-table-column>
      <el-table-column label="任务执行人" align="center" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.productionUserName) }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, watch } from "vue";
import { listCheckProcessApi } from "@/api/reportCheck";
import { selectDictLabel } from "@/utils/ruoyi";
import { blankAttributeDefault } from "@/utils/index";
import { useRouter } from "vue-router";

const props = defineProps({
  taskStatus: {
    type: Number,
    default: -1,
  },
  planStartDate: {
    type: String,
    default: undefined,
  },
  planEndDate: {
    type: String,
    default: undefined,
  },
  createName: {
    type: String,
    default: undefined,
  },
});

const { proxy } = getCurrentInstance();
const router = useRouter();
const { check_type, data_status } = toRefs(
  proxy.useDict("check_type", "data_status")
);
const tableList = ref([]);
// 获取检验分页列表
const getList = async () => {
  // 参数
  let dic = {};
  if (props.taskStatus && props.taskStatus != -1) {
    dic["checkType"] = props.taskStatus;
  }
  if (props.planStartDate && props.planStartDate != null) {
    dic["startCheckedTime"] = props.planStartDate;
  }
  if (props.planEndDate && props.planEndDate != null) {
    dic["endCheckedTime"] = props.planEndDate;
  }
  if (props.createName && props.createName != null) {
    dic["createName"] = props.createName;
  }
  const res = await listCheckProcessApi(dic);
  tableList.value = res.data;
};
getList();

/** 跳转检验单详情 */
const pushCheckDetails = (row) => {
  router.push({ path: "/detection-edit", query: { id: row.id } });
};

watch(
  () => props.taskStatus,
  () => {
    console.log(props.taskStatus);
    getList();
  }
);

watch(
  () => props.planStartDate,
  () => {
    console.log(props.planStartDate);
    getList();
  }
);

watch(
  () => props.planEndDate,
  () => {
    getList();
  }
);

watch(
  () => props.createName,
  () => {
    getList();
  }
);
</script>

<style lang="scss" scoped>
@include task-table;
</style>
